home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / utils1 / fip09.arj / SOURCE.ZIP / CALCULAT.CPP next >
C/C++ Source or Header  |  1993-11-17  |  4KB  |  92 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module calculat.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/c/fips/source/cpp/RCS/calculat.cpp 0.9.1.1 1993/11/17 17:51:01 schaefer Exp schaefer $
  8.  
  9.     Copyright (C) 1993 Arno Schaefer
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26.     Report problems and direct all questions to:
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de
  29. */
  30.  
  31. #include "hdstruct.h"
  32. #include "fipsspec.h"
  33.  
  34. /* ----------------------------------------------------------------------- */
  35. /* Some calculations                                                       */
  36. /* ----------------------------------------------------------------------- */
  37.  
  38. void fips_partition_table::calculate_new_root (dword new_start_cylinder,int partition_no,const drive_geometry &geometry)
  39. {
  40.     struct partition_info tmppart;
  41.  
  42.     for (int i=0;i<3;i++) if (!partition_info[i].system)
  43.     {
  44.         for (int j=i+1;j<4;j++) if ((partition_info[j].system == 1) || (partition_info[j].system == 4) || (partition_info[j].system == 6))
  45.         {
  46.             tmppart = partition_info[i];
  47.             partition_info[i] = partition_info[j];
  48.             partition_info[j] = tmppart;
  49.             if (partition_no == j) partition_no = i;
  50.             break;
  51.         }
  52.     }
  53.     for (i=0;i<4;i++) if (!partition_info[i].system) break;
  54.  
  55.     partition_info[i].bootable = 0;
  56.     partition_info[i].end_sector = partition_info[partition_no].end_sector;
  57.     partition_info[i].end_head = partition_info[partition_no].end_head;
  58.     partition_info[i].end_cylinder = partition_info[partition_no].end_cylinder;
  59.     partition_info[i].start_sector = 1;
  60.     partition_info[i].start_head = 0;
  61.     partition_info[i].start_cylinder = new_start_cylinder;
  62.     partition_info[i].start_sector_abs = new_start_cylinder * geometry.heads * geometry.sectors;
  63.     partition_info[i].no_of_sectors_abs = partition_info[partition_no].start_sector_abs + partition_info[partition_no].no_of_sectors_abs - partition_info[i].start_sector_abs;
  64.  
  65.     if ((partition_info[i].no_of_sectors_abs > 0xffff) || (partition_info[i].start_sector_abs > 0xffff)) partition_info[i].system = 6;
  66.         else if (partition_info[i].no_of_sectors_abs >= 20740) partition_info[i].system = 4;
  67.         else partition_info[i].system = 1;
  68.  
  69.     partition_info[partition_no].end_head = geometry.heads - 1;
  70.     partition_info[partition_no].end_sector = geometry.sectors;
  71.     partition_info[partition_no].end_cylinder = new_start_cylinder - 1;
  72.     partition_info[partition_no].no_of_sectors_abs = partition_info[i].start_sector_abs - partition_info[partition_no].start_sector_abs;
  73.     if ((partition_info[partition_no].no_of_sectors_abs > 0xffff) || (partition_info[partition_no].start_sector_abs > 0xffff)) partition_info[partition_no].system = 6;
  74.     else partition_info[partition_no].system = 4;
  75. }
  76.  
  77.  
  78. void fips_bpb::calculate_new_boot (const partition_info &partition_info)
  79. {
  80.     if ((partition_info.no_of_sectors_abs > 0xffff) || (partition_info.start_sector_abs > 0xffff))
  81.     {
  82.         no_of_sectors = 0;
  83.         no_of_sectors_long = partition_info.no_of_sectors_abs;
  84.     }
  85.     else
  86.     {
  87.         no_of_sectors_long = 0;
  88.         no_of_sectors = partition_info.no_of_sectors_abs;
  89.     }
  90. }
  91.  
  92.